package com.jingdianjichi.oss.controller;

/*
* OssController
* */

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.jingdianjichi.oss.adapter.StorageAdapter;
import com.jingdianjichi.oss.service.FileService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.xml.transform.Result;
import java.util.List;

@RestController
public class FileController {

    @Resource
    private FileService fileService;

    @NacosValue(value = "${storage.service.type}",autoRefreshed = true)
    private String storageType;

    @RequestMapping("/testgetAllBucket")
    public String getAllBucket() throws Exception {
        List<String> bucket = fileService.listBucket();
        return bucket.get(0);
    }

    /*
    * 获取文件url
    * */
    @PostMapping("/getUrl")
    public String getUrl(String buckName,String objectName){
        return fileService.getUrl(buckName,objectName);
    }

    /*
    * 上传文件
    * */
    @PostMapping("/uploadFile")
    public String uploadFile(MultipartFile multipartFile, String buckName, String objectName){
        String url = fileService.uploadFile(multipartFile, buckName, objectName);
        return url;
    }

    @RequestMapping("/testNacos")
    public String testNacos(){
        return storageType;
    }
}
